package Logicamente;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Dimension;
import java.awt.Cursor;

import org.eclipse.wb.swing.FocusTraversalOnArray;

import java.awt.Component;
import java.awt.event.ActionEvent;

import javax.swing.SwingConstants;

import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class DialogoCompartir extends JDialog {

	private JPanel contentPane;
	private VentanaFinDeJuego ventanaPadre;
	private JButton btnFacebook;
	private JButton btnInstagram;
	private JButton btnTwitter;
	private JButton btnG;
	private JButton cancelButton;


	/**
	 * Create the dialog.
	 */
	public DialogoCompartir(VentanaFinDeJuego v) {
		ventanaPadre = v;
		setTitle("Compartir");
		this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanelConFondo("/Imagenes/fondo.jpg");
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		JPanel panel_superior = new JPanelConFondo("/Imagenes/fondo_t.png");
		panel_superior.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(panel_superior, BorderLayout.CENTER);
		GridBagLayout gbl_panel_superior = new GridBagLayout();
		gbl_panel_superior.columnWidths = new int[]{0, 0, 0, 0, 0};
		gbl_panel_superior.rowHeights = new int[]{0, 0, 0, 0, 0};
		gbl_panel_superior.columnWeights = new double[]{100.0, 0.0, 0.0, 100.0, Double.MIN_VALUE};
		gbl_panel_superior.rowWeights = new double[]{100.0, 0.0, 0.0, 100.0, Double.MIN_VALUE};
		panel_superior.setLayout(gbl_panel_superior);
		{
			btnFacebook = new JButton("");
			btnFacebook.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					boton(arg0,"/Imagenes/compartir_facebook.png");
				}
			});
			btnFacebook.setMargin(new Insets(0, 1, 0, 0));
			btnFacebook.setAlignmentX(Component.CENTER_ALIGNMENT);
			btnFacebook.setHorizontalTextPosition(SwingConstants.CENTER);
			btnFacebook.setIcon(new ImageIcon(DialogoCompartir.class.getResource("/Imagenes/boton_facebook_f.png")));
			btnFacebook.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			btnFacebook.setPreferredSize(new Dimension(75, 75));
			GridBagConstraints gbc_btnFacebook = new GridBagConstraints();
			gbc_btnFacebook.insets = new Insets(0, 0, 5, 5);
			gbc_btnFacebook.gridx = 1;
			gbc_btnFacebook.gridy = 1;
			panel_superior.add(btnFacebook, gbc_btnFacebook);
		}
		{
			btnInstagram = new JButton("");
			/**btnInstagram.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					boton(arg0,"/Imagenes/compartir_instagram.png");
				}
			});**/
			btnInstagram.setIcon(new ImageIcon(DialogoCompartir.class.getResource("/Imagenes/boton_instagram_f.png")));
			btnInstagram.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			btnInstagram.setPreferredSize(new Dimension(75, 75));
			GridBagConstraints gbc_btnInstagram = new GridBagConstraints();
			gbc_btnInstagram.insets = new Insets(0, 0, 5, 5);
			gbc_btnInstagram.gridx = 2;
			gbc_btnInstagram.gridy = 1;
			panel_superior.add(btnInstagram, gbc_btnInstagram);
		}
		{
			btnTwitter = new JButton("");
			btnTwitter.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					boton(arg0,"/Imagenes/compartir_twitter.png");
				}
			});
			btnTwitter.setIcon(new ImageIcon(DialogoCompartir.class.getResource("/Imagenes/boton_twitter_f.png")));
			btnTwitter.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			btnTwitter.setPreferredSize(new Dimension(75, 75));
			GridBagConstraints gbc_btnTwitter = new GridBagConstraints();
			gbc_btnTwitter.insets = new Insets(0, 0, 5, 5);
			gbc_btnTwitter.gridx = 1;
			gbc_btnTwitter.gridy = 2;
			panel_superior.add(btnTwitter, gbc_btnTwitter);
		}
		{
			btnG = new JButton("");
			btnG.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					boton(arg0,"/Imagenes/compartir_g+.png");
				}
			});
			btnG.setIcon(new ImageIcon(DialogoCompartir.class.getResource("/Imagenes/boton_g+_f.png")));
			btnG.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			btnG.setPreferredSize(new Dimension(75, 75));
			GridBagConstraints gbc_btnG = new GridBagConstraints();
			gbc_btnG.insets = new Insets(0, 0, 5, 5);
			gbc_btnG.gridx = 2;
			gbc_btnG.gridy = 2;
			panel_superior.add(btnG, gbc_btnG);
		}
		{
			JPanel buttonPane = new JPanelConFondo("/Imagenes/fondo_t.png");
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JLabel lblVolver = new JLabel("Volver");
				buttonPane.add(lblVolver);
			}
			{
				cancelButton = new JButton("");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						actionCancelButton(arg0);
					}
				});
				cancelButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
				cancelButton.setIcon(new ImageIcon(DialogoCompartir.class.getResource("/Imagenes/boton_volver_f.png")));
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
		setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{btnFacebook, btnInstagram, btnTwitter, btnG, cancelButton}));
	}
	
	@SuppressWarnings("deprecation")
	protected void boton(ActionEvent evt, String s) {
		DialogoRedSocial v = new DialogoRedSocial(s,this);
		v.setLocationRelativeTo(null);
		v.setVisible(true);
		this.activar(false);
	}
	
	public void activar(boolean b)
	{
		cancelButton.setEnabled(b);
		btnFacebook.setEnabled(b);
		btnInstagram.setEnabled(b);
		btnTwitter.setEnabled(b);
		btnG.setEnabled(b);
	}
	
	private void actionCancelButton(ActionEvent evt)
	{
		this.setVisible(false);
		this.hide();
		ventanaPadre.activar(true);
	}
}
